package ibmetp.mis.controller.role;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.ResToRoleService;
import ibmetp.mis.service.UserToRoleService;
import ibmetp.mis.serviceImpl.ResToRoleServiceImpl;
import ibmetp.mis.serviceImpl.UserToRoleServiceImpl;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class RoleAddResServlet
 */
public class RoleAddResServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RoleAddResServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		System.out.println("Call RoleAddResServlet...");
		//获取参数
		String resourceIds=request.getParameter("resourceIds")==null?"":request.getParameter("resourceIds");
		String roleIds=request.getParameter("roleIds")==null?"":request.getParameter("roleIds");
		//用户添加角色
		ResToRoleService rr=new ResToRoleServiceImpl();
		String result=rr.addResRole(roleIds, resourceIds);	
		//如果有返回消息，则将消息发回页面
		if(result!=null){		
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
	}

}
